{extend name='admin'}
{block name='css'}
<link href="{:asset('HHuploadify-master/dist/HHuploadify.css')}" rel="stylesheet" type="text/css" >
<script src="{:asset('HHuploadify-master/dist/HHuploadify.js')}" type="text/javascript" ></script>
{/block}
{block name='content'}
<form class="row" action="{:url('admin/blog/blogadd')}" method="post" id="myform">
    <div class="col-md-9">
        <div class="form-group">
            <label for="name">标题</label>
            <input id="name" class="form-control input-lg" name="name" type="text" placeholder="文章标题">
        </div>
        <div class="form-group">
            <label for="body">内容</label>
            <textarea name="neirong" id="body" rows="3"></textarea>
        </div>
    </div>
    <div class="col-md-3">
        <div class="form-group">
            <label for="author">作者</label>
            <input id="author" class="form-control" name="author" type="text" placeholder="admin">
        </div>
        <div class="form-group">
            <label for="goodslogo">博文图片</label>
        </div>
        <div class="form-group">
            <div class="col-sm-6" id="goodslogo">
            </div>
            <input type="hidden" name="image" id="goods_logo"/>
        </div>
        <div class="form-group">
            <select id="category" class="form-control" name="cid">
                {foreach $date as $item}
                <option name="{$item.id}" value="{$item.id}">{$item.title}</option>
                {/foreach}
            </select>
        </div>
        <div class="form-group">
            <input class="btn btn-info link-update" value="添加" type="submit">
            <a class="btn btn-danger link-del" href="{:url('admin/blog/index')}">返回</a>
        </div>
    </div>
</form>
{/block}
{/extend}
{block name='js'}
<script type="text/javascript" src="{:asset('admin/ueditor/ueditor.config.js')}"></script>
<script type="text/javascript" src="{:asset('admin/ueditor/ueditor.all.js')}"></script>
<script type="text/javascript" >
    var ue =UE.getEditor('body',{
        initialFrameHeight:200
    })
</script>
<script type="text/javascript" >
    $(function(){
        new HHuploadify({
            container:'#goodslogo',
            single:true,
            chooseText:'选取图片',
            auto:true,
            url:"{:url('admin/blog/update')}",
            field:'image',
            //上传成功后的回调函数
            onUploadSuccess:function(file,data){
                var obj =JSON.parse(data);
                if(obj.status=='success'){
                    $('#goods_logo').val(obj.logo);
                }else{
                    layer.msg('上传图片失败',{icon:5,time:1000});
                }
            },
            onRemoved:function(){
                $('#goods_logo').val('');
            }
        });
        $('#myform').submit(function(evt){
            evt.preventDefault();
            var shuju =$(this).serialize();
            $.ajax({
                url:"#",
                type:'post',
                data:shuju,
                dataType:'json',
                success:function(msg){
                    console.log(msg);
                    if(msg==1){
                        layer.alert('添加成功',{icon:6},function(){
                            location.href="{:url('admin/blog/index')}";
                        })
                    }else{
                        layer.alert(msg,{icon:5})
                    }
                }
            })
        })
    })
</script>
{/block}